class TextShow {
  public p: HTMLElement
  constructor(x: number, y: number, destroyTime = 1000) {
    const p = document.createElement('p')
    this.p = p
    this.createElement(x, y)
    this.destroy(destroyTime)
  }
  createElement(x: number, y: number) {
    const p = this.p
    p.className = 'text-show'
    p.innerText = this.randomText()
    p.style.color = this.randomArColor()
    p.style.left = x + 'px'
    p.style.top = y - 12 + 'px'
    document.body.append(this.p)
  }
  destroy(destroyTime: number) {
    setTimeout(() => {
      this.p.remove()
    }, destroyTime)
  }
  randomText() {
    const textList = ['哈哈哈哈😄', '鑫哥好帅～😊', '亲，别太关注程序的异常了😫', '你怎么还没有来找我😭', '你在养鱼嘛🐟', '雅俗共赏，君子好求🚺']
    const len = textList.length
    const random = Math.floor(Math.random() * len)
    return textList[random]
  }
  randomArColor() {
    const { floor, random } = Math
    return `rgba(${floor(random() * 256)},${floor(random() * 256)},${floor(random() * 256)},${0.6})`;
  }
}

export default TextShow